package com.taotao.controller;

import com.taotao.springboot.SpringbootTest;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.config.Configurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @GetMapping("test")
    public void test() throws InterruptedException {
        Logger logger = LoggerFactory.getLogger(SpringbootTest.class);

        while (true) {
            Thread.sleep(1000);
            logger.info("info");
            logger.debug("debug");
        }
    }

    @GetMapping("update")
    public void update() {
        // 获取根Logger
        org.apache.logging.log4j.Logger rootLogger = LogManager.getRootLogger();

        // 设置全局日志级别为INFO
        Configurator.setAllLevels(rootLogger.getName(), Level.DEBUG);
    }
}
